package com.nenglai.admin.modular.report.controller;

import com.nenglai.admin.modular.report.form.TemplateForm;
import com.nenglai.admin.modular.report.service.ReportTemplateService;
import com.nenglai.common.jwt.VerifyToken;
import com.nenglai.common.response.Result;
import com.nenglai.common.response.ResultGenerator;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author kongdehui
 * @date 2021/06/18 14:45
 **/
@RestController
@RequestMapping("backend/report-template")
public class ReportTemplateController {

    @Resource
    ReportTemplateService reportTemplateService;

    @VerifyToken
    @PostMapping("add")
    public Result<?> add(@RequestParam("file") MultipartFile file, @Valid TemplateForm form) {
        boolean flag = reportTemplateService.add(file, form);
        return ResultGenerator.successOrError(flag, "success", "fail");
    }

    @VerifyToken
    @PostMapping("update")
    public Result<?> update(@RequestParam(value = "file", required = false) MultipartFile file, @Valid TemplateForm form) {
        boolean flag = reportTemplateService.update(file, form);
        return ResultGenerator.successOrError(flag, "success", "fail");
    }
}
